package com.interfaces;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import com.entity.Item;

/**   
* @Title: ItemDao.java 
* @Package com.interfaces 
* @author 孙梦楠 
* @date 2017年8月18日 下午1:23:53 
* @version V1.0.0   
*/

public interface ItemDao extends JpaRepository<Item, Integer>{
	
	////给DateitemID查到Item列表
	@Transactional
	@Query(value = "SELECT * FROM e_item i WHERE i.item_id IN (SELECT di.item_id FROM r_dataitem_item di WHERE di.dataitem_id=?1)",nativeQuery=true)
	public List<Item> listItemByDateitemid(Integer dataitemid);
	
	////给Taskid查到Item列表
	@Transactional
	@Query(value = "SELECT * FROM e_item i WHERE i.item_id IN (SELECT ti.item_id FROM r_task_item ti WHERE ti.task_id=?1)",nativeQuery=true)
	public List<Item> listItemByTaskid(Integer taskid);
	
//	//条件列表
//	@Transactional
//	@Query(value = "SELECT i FROM Item i WHERE (i.name =?1 OR ?1 IS NULL) AND (i.code =?2 OR ?2 IS NULL) "
//			+ "AND (i.len =?3 OR ?3 IS NULL) AND (i.protocoltype = ?4)")
//	public List<Item> findByConditions(String name,String code,String len, String protocoltype);
	
	
	List<Item> findByProtocoltype(String protocoltype);

}
